package com.shy.springframework.test.common;

import com.shy.springframework.beans.BeansException;
import com.shy.springframework.beans.factory.config.BeanPostProcessor;
import com.shy.springframework.test.bean.UserService;

/**
 * @author yzpang
 * @desc:
 * @date: 2023/2/8 14:04
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("userService".equals(beanName)){
            UserService userService = (UserService) bean;
            userService.setLocation("改为: 合肥");
        }
        System.out.println("bean初始化之前执行...beanName: " + beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("bean初始化之后执行...beanName: " + beanName);
        return bean;
    }
}
